package simtester.server

import java.util.Date;
import java.util.List;

import org.bson.types.ObjectId;

class TestSuite {
    static belongsTo = [owner: User, team: Team]
    static hasMany = [testcases: TestCase]

    String name
    String type
    Date dateCreated
    Date lastUpdated
    List<Category> categories = []

    static constraints = {
    }
    
    static embedded = ['categories']
    
    def findCatValue(category) {
        def cat = categories.find { it.name == category }
        
        if (cat) {
            cat.value
        } else {
            null
        }
    }
    
    def findCatNames() {
        categories.collect { it.name }
    }
    
    def setCategory(key, value) {
        def cat = categories.find { it.name == key }
        if (cat) {
            cat.value = value
        } else {
            categories << new Category(name: key, value: value)
        }
    }
}
